package com.enjoy.udp.acceptside;

import com.enjoy.udp.broadcast.LogMsg;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * Created by HP on 2019/7/15.
 * 实际的业务处理类
 */
public class LogEventHandler extends SimpleChannelInboundHandler<LogMsg> {
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, LogMsg logMsg) throws Exception {
        //创建 StringBuilder，并且构建输出的字符串
        StringBuilder builder = new StringBuilder();
        builder.append(logMsg.getTime());
        builder.append(" [");
        builder.append(logMsg.getSource().toString());
        builder.append("] ：[");
        builder.append(logMsg.getMsgId());
        builder.append("] ：");
        builder.append(logMsg.getMsg());
        //打印 LogMsg 的数据
        System.out.println(builder.toString());
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        super.exceptionCaught(ctx, cause);
    }
}
